package data 
{
	import cn.inswf.utils.tag.ITag;
	import flash.utils.getTimer;
	/**
	 * ...
	 * @author lee
	 */
	public class Lesson 
	{
		public static const NONE:String = "n";
		public static const INCOMPLETE:String = "i";
		public static const COMPLETE:String = "c";
		
		public static var index:int;
		//config
		public var control:int = 0;
		public var notMovie:Boolean;
		//config
		
		//章id
		public var chapter:int;
		//节id
		public var lessonId:int;
		//节名
		public var name:String;
		//文件名
		public var path:String;
		//////////////////////////
		//文件顺序id
		public var id:int;
		////平台用
		//课程学习状态，"n"未观看，"i"未完成，"c"完成，"p"通过，"f"失败（不及格）
		public var status:String = NONE;
		//得分
		public var score:int;
		public var test:String = "";
		public var time:Number;
		private var _startTime:Number;
		public function Lesson() 
		{
			id = index;
			index++;
		}
		public function start():void {
			if (status != COMPLETE) {
				status = INCOMPLETE;
				_startTime = getTimer();
			}
		}
		public function addScore():void {
			score++;
		}
		public function complete():void {
			if (status == INCOMPLETE) {
				status = COMPLETE;
				time = getTimer()-_startTime;
			}
		}
		public function hasComplete():Boolean {
			return status == COMPLETE;
		}
		public function parse(xml:XML):void {
			name = xml.attribute("name");
			path = xml.attribute("filePath");
			var xmlcontrol:String = xml.attribute("control");
			if (xmlcontrol != "") {
				control = parseInt(xmlcontrol);
			}
			var movie:String = xml.attribute("control");
			if (movie != "") {
				notMovie = true;
			}
		}
		public function getAiccData():String {
			var str:String = "";
			str += "J_ID." + id + "=" + id+"\r\n";
			str += "J_status." + id + "=" + status+"\r\n";
			str += "J_score." + id + "=" + score+"\r\n";
			str += "J_test." + id + "=" + test+"\r\n";
			return str;
		}
		public function setAiccData(value:String):void {
			if (value != null) {
				var p:Array = value.split("\r\n");
				var len:int = p.length;
				var lst:Array = [];
				for (var i:int = 0; i < len; i++) {
					var s:String = p[i];
					var sarr:Array = s.split("=");
					lst[i] = sarr[1];
				}
				status = lst[1];
				score = lst[2];
				test = lst[3];
			}
			
		}
		public function getScormData():String {
			return id + "_" + status + "_" + score + "_" + test;
		}
		public function setScormData(value:String):void {
			if (value != null) {
				var p:Array = value.split("_");
				status = p[1];
				score = p[2];
				test = p[3];
			}
		}
		public function getLocalData():Object {
			var obj:Object = { };
			obj["id"] = id;
			obj["status"] = status;
			obj["score"] = score;
			obj["test"] = test;
			return obj;
		}
		public function setLocalData(value:Object):void {
			if (value == null) return;
			status = value["status"];
			score = value["score"];
			test = value["test"];
		}
	}

}